package com.ruoyi.system.domain.bo;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.system.domain.SysTenantPackage;

import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import jakarta.validation.constraints.*;
import java.io.Serializable;
import java.util.Arrays;

/**
 * 租户套餐业务对象 sys_tenant_package
 *
 * @author Michelle.Chung
 */

@Data
@EqualsAndHashCode(callSuper = false)
@AutoMapper(target = SysTenantPackage.class, reverseConvertGenerate = false)
public class SysTenantPackageBo extends SysTenantPackage implements Serializable {

    /**
     * 关联菜单id
     */
    @JsonDeserialize(using = MenuIdsDeserializer.class)
    private String menuIds;

    /**
     * 获取菜单ID数组
     */
    public Long[] getMenuIdArray() {
        if (StringUtils.isEmpty(menuIds)) {
            return new Long[0];
        }
        return Arrays.stream(menuIds.split(","))
            .map(Long::valueOf)
            .toArray(Long[]::new);
    }

    /**
     * 设置菜单ID数组
     */
    public void setMenuIdArray(Long[] menuIds) {
        if (menuIds == null || menuIds.length == 0) {
            this.menuIds = "";
        } else {
            this.menuIds = StringUtils.join(menuIds, ",");
        }
    }

    /**
     * 套餐名称
     */
    @NotBlank(message = "套餐名称不能为空")
    @Override
    public String getPackageName() {
        return super.getPackageName();
    }
}
